﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Common.UI
{
    public partial class InputForm : Form
    {
        public InputForm()
        {
            InitializeComponent();
        }
        public static DialogResult Show(out string? result, string info = "请输入：", string title = "输入", string defaultText = "", char? passwordChar = null, FormStartPosition postion = FormStartPosition.CenterParent)
        {
            using (InputForm InputBox = new InputForm())
            {
                InputBox.Text = title;
                InputBox.lblInfo.Text = info;
                InputBox.txtBoxInput.Text = defaultText;
                if (passwordChar != null)
                    InputBox.txtBoxInput.PasswordChar = (char)passwordChar;
                InputBox.StartPosition = postion;
                DialogResult dialogResult = InputBox.ShowDialog();
                if (dialogResult == DialogResult.OK)
                {
                    result = InputBox.txtBoxInput.Text;
                }
                else
                {
                    result = null;
                }
                return dialogResult;
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void InputForm_Load(object sender, EventArgs e)
        {
            this.txtBoxInput.Focus();
        }
    }
}
